# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Contributor: Y7n05h < echo WTduMDVoQHk3bjA1aC5kZXY= | base64 -d >

pkgname=pwru
pkgver=1.0.3
pkgrel=1
pkgdesc="Packet, where are you? -- eBPF-based Linux kernel networking debugger"
arch=("loong64" "x86_64")
url="https://github.com/cilium/pwru"
license=("GPL2")
depends=("glibc")
makedepends=("clang" "llvm" "go")
source=("$pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz")
sha256sums=('19317ceb2ae330e28b5f969ab1ed64e6f665f89773437dfdca1d24b4dea811f7')

prepare() {
	cd "$pkgname-$pkgver"
	export CGO_CPPFLAGS="${CPPFLAGS}"
	export CGO_CFLAGS="${CFLAGS}"
	export CGO_CXXFLAGS="${CXXFLAGS}"
	export CGO_LDFLAGS="${LDFLAGS}"
	export GOPATH="${srcdir}"
	export GOFLAGS="-buildmode=pie -mod=vendor -modcacherw"
	export TARGET_GOARCH=amd64
	go generate
}

build() {
	cd "$pkgname-$pkgver"
	export CGO_CPPFLAGS="${CPPFLAGS}"
	export CGO_CFLAGS="${CFLAGS}"
	export CGO_CXXFLAGS="${CXXFLAGS}"
	export CGO_LDFLAGS="${LDFLAGS}"
	export GOPATH="${srcdir}"
	export GOFLAGS="-buildmode=pie -mod=vendor -modcacherw"
	make libpcap/libpcap.a
	go build \
		-ldflags "-compressdwarf=false -linkmode external -X \"github.com/cilium/pwru/internal/pwru.Version=${pkgver}\"" \
		-o ${pkgname}
}

package() {
	cd "$pkgname-$pkgver"
	install -Dm755 ${pkgname} -t "$pkgdir/usr/bin"
}
